<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>画布</title>
  <style>
    canvas {
      border: 1px solid #333;
    }
  </style>
</head>
<body>
  <canvas id="app" width="500" height="500"></canvas>
</body>
<script>
  window.onload = function() {
    // 1.获取画布节点对象
    var canvas = document.querySelector('#app');
    // 2.获取画布的上下文对象（画笔）
    var context = canvas.getContext('2d');
    // 3.绘制 x,y,width,height
    // 设置绘制样式
    context.strokeStyle = 'teal';
    context.lineWidth = 5;
    context.fillRect(10,10,100,100);
    // context.strokeRect(10,10,100,100);
    // 4.清楚部分、全部画布
    // context.clearRect(10,10,50,50);
    context.clearRect(0,0,500,500);
  }
</script>
</html>